CSharpTest.Net
KeyValueComparer<TKey,TValue> Constructor()
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > KeyValueComparer<TKey,TValue> Class > KeyValueComparer<TKey,TValue> Constructor : KeyValueComparer<TKey,TValue> Constructor()

Glossary Item Box

Creates a key-value comparison using the default comparer for type TKey

Syntax

Visual Basic (Declaration) 
Public Function New()
C# 
public KeyValueComparer<TKey,TValue>()

Example

Library/Library.Test/TestOrderedEnumeration.cs

C#Copy Code
KeyValueComparer<int, int> cmp = new KeyValueComparer<int, int>();
Assert.IsTrue(ReferenceEquals(Comparer<int>.Default, cmp.Comparer));
Assert.IsTrue(ReferenceEquals(Comparer<int>.Default, KeyValueComparer<int, int>.Default.Comparer));

Assert.AreEqual(-1, cmp.Compare(new KeyValuePair<int, int>(1, 1), new KeyValuePair<int, int>(2, 1)));
Assert.AreEqual(0, cmp.Compare(new KeyValuePair<int, int>(1, 1), new KeyValuePair<int, int>(1, 2)));
Assert.AreEqual(1, cmp.Compare(new KeyValuePair<int, int>(2, 1), new KeyValuePair<int, int>(1, 1)));
VB.NETCopy Code
Dim cmp As New KeyValueComparer(Of Integer, Integer)()
Assert.IsTrue(ReferenceEquals(Comparer(Of Integer).[Default], cmp.Comparer))
Assert.IsTrue(ReferenceEquals(Comparer(Of Integer).[Default], KeyValueComparer(Of Integer, Integer).[Default].Comparer))

Assert.AreEqual(-1, cmp.Compare(New KeyValuePair(Of Integer, Integer)(1, 1), New KeyValuePair(Of Integer, Integer)(2, 1)))
Assert.AreEqual(0, cmp.Compare(New KeyValuePair(Of Integer, Integer)(1, 1), New KeyValuePair(Of Integer, Integer)(1, 2)))
Assert.AreEqual(1, cmp.Compare(New KeyValuePair(Of Integer, Integer)(2, 1), New KeyValuePair(Of Integer, Integer)(1, 1)))

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys